// pages/success/success.js
const app = getApp()
var url = require('../../utils/url.js');
var token;
var interval;
var time=3;
Page({

  /**
   * 页面的初始数据
   */
  data: {
     type:1,
     jifen: "",
     time:"3秒"
  },
  getJifen() {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: url.URl + 'my/jifen',
      data: {},
      method: 'get',
      header: {
        'Authorization': token
      },
      success: function (res) {
        console.log(res)
        wx.hideLoading()
        var msg = res.data.msg
        if (res.data.code == 200) {
          that.setData({
            jifen: res.data.data
          })
        } else {
          wx.showToast({
            title: msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  toIndex:function(){
     wx.switchTab({
       url: '/pages/index/index',
       success: function(res) {},
       fail: function(res) {},
       complete: function(res) {},
     })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var that = this;
     var type=options.type;
     this.setData({
       type:type
     })
     if(type==2){
       interval = setInterval(function () {
         time--;
         that.setData({
           time: time + '秒'
         })
         if (time == 0) {
           clearInterval(interval)
           wx.redirectTo({
             url: '/pages/luckyStar/luckyStar',
             success: function (res) { },
             fail: function (res) { },
             complete: function (res) { },
           })
         }
       }, 1000)
     }
    wx.getStorage({
      key: 'token',
      success: function (res) {
        token = res.data;
        that.getJifen()
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    time = 3;
    clearInterval(interval)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})